﻿using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Camc.Quality.Quality.TransformHtml;
using Camc.Quality.RecordTable.FormClass;
using Camc.Quality.RecordTable.FormEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.Quality.FormManage
{
    public class FirstFormManage : DomainService
    {
        private readonly IRepository<具有证明书的主要零件记录表, Guid> _mainPartsRepository;
        private readonly IRepository<舱口盖开闭记录表, Guid> _hatchRepository;
        private readonly IRepository<通用力矩复校记录表, Guid> _momentRecordRepository;
        private readonly IRepository<力矩记录表, Guid> _momentRepository;
        private readonly IRepository<通用多媒体记录表, Guid> _multiMediaRepository;
        private readonly IRepository<通用总装数据记录表, Guid> _totalDataRepository;
        private readonly IRepository<胶液配比情况记录表, Guid> _liquidRatioRepository;
        private readonly IRepository<质量控制记录表, Guid> _controlrecordRepository;
        private readonly IRepository<进箱舱登记表, Guid> _enterRegisterRepository;
        private readonly IRepository<通用记录表, Guid> _generalRecordsRepository;

        public FirstFormManage(
           IRepository<具有证明书的主要零件记录表, Guid> mainPartsRepository,
           IRepository<舱口盖开闭记录表, Guid> hatchRepository,
           IRepository<通用力矩复校记录表, Guid> momentRecordRepository,
           IRepository<力矩记录表, Guid> momentRepository,
           IRepository<通用多媒体记录表, Guid> multiMediaRepository,
           IRepository<通用总装数据记录表, Guid> totalDataRepository,
           IRepository<胶液配比情况记录表, Guid> liquidRatioRepository,
           IRepository<质量控制记录表, Guid> controlrecordRepository,
           IRepository<进箱舱登记表, Guid> enterRegisterRepository,
           IRepository<通用记录表, Guid> generalRecordsRepository
           )
        {
            _mainPartsRepository = mainPartsRepository;
            _hatchRepository = hatchRepository;
            _momentRecordRepository = momentRecordRepository;
            _momentRepository = momentRepository;
            _multiMediaRepository = multiMediaRepository;
            _totalDataRepository = totalDataRepository;
            _liquidRatioRepository = liquidRatioRepository;
            _controlrecordRepository = controlrecordRepository;
            _enterRegisterRepository = enterRegisterRepository;
            _generalRecordsRepository = generalRecordsRepository;
        }

        public async Task CreateTable(string formType,Guid processinfoId,string key ,string value,Guid workStepId,int tableindex)
        {
            var baseList = TableToData.ConvertToBaseRecord(processinfoId, key, value, workStepId, tableindex);
            switch (formType)
            {
                case "juyouzhengmingshudezhuyaolingjianjilubiao"://具有证明书的主要零件记录表
                    foreach (var item in baseList)
                    {
                        具有证明书的主要零件记录表 record = new 具有证明书的主要零件记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.FisrtDrawingNum, item.FirstDrawingName, item.SecondDrawingNum, item.Certificate);
                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.Remarks);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _mainPartsRepository.InsertAsync(record);
                    }
                    break;
                case "cangkougaikaibijilubiao"://舱口盖开闭记录表
                    foreach (var item in baseList)
                    {
                        舱口盖开闭记录表 record = new 舱口盖开闭记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.FisrtDrawingNum, item.FirstDrawingName, item.ProductNum, item.RecordItem, item.ToolUsed);

                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.RecordLocation);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstMeasuredValues);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _hatchRepository.InsertAsync(record);
                    }
                    break;
                case "lijufujiaojilubiao"://力矩复校记录表
                    foreach (var item in baseList)
                    {
                        通用力矩复校记录表 record = new 通用力矩复校记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.FisrtDrawingNum, item.SecondDrawingNum, item.ToolUsed);

                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.ProcessorDemand, item.Remarks);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstMeasuredValues, item.SecondMeasuredValues);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _momentRecordRepository.InsertAsync(record);
                        //momentrecordlist.Add(record);
                    }
                    break;
                case "lijujilubiao"://力矩记录表
                    foreach (var item in baseList)
                    {
                        力矩记录表 record = new 力矩记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.FisrtDrawingNum, item.SecondDrawingNum, item.ToolUsed);

                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.DesignerDemand, item.ProcessorDemand, item.Remarks);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstMeasuredValues);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _momentRepository.InsertAsync(record);
                        //momentlist.Add(record);
                    }
                    break;
                case "duomeitijilubiao"://多媒体记录表
                    foreach (var item in baseList)
                    {
                        通用多媒体记录表 record = new 通用多媒体记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.RecordElement);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.RecordLocation, item.RecordRequire);
                        record.MultiMedia = record.SetMultiMedia(new MultiMediaEntity(), item.PhotoNo);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstConfirmResult);
                        await _multiMediaRepository.InsertAsync(record);
                        //multimedialist.Add(record);
                    }
                    break;
                case "zongzhuangshujujilubiao"://总装数据记录表
                    foreach (var item in baseList)
                    {
                        通用总装数据记录表 record = new 通用总装数据记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.FirstDrawingName, item.RecordElement, item.ToolUsed);
                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.DesignerDemand, item.ProcessorDemand, item.Remarks);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstMeasuredValues);
                        record.Environment = record.SetEnvironment(new EnvironmentEntity(), item.Temperature, item.Humidity);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _totalDataRepository.InsertAsync(record);
                        //totalDatalist.Add(record);
                    }
                    break;
                case "jiaoyepeibiqingkuangjilubiao"://胶液配比情况记录表
                    foreach (var item in baseList)
                    {
                        胶液配比情况记录表 record = new 胶液配比情况记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.RecordElement, item.FisrtDrawingNum);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.MeasuredActual);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _liquidRatioRepository.InsertAsync(record);
                        //liquidRatiolist.Add(record);
                    }
                    break;
                case "zhiliangkongzhijilubiao"://质量控制记录表
                    foreach (var item in baseList)
                    {
                        质量控制记录表 record = new 质量控制记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _controlrecordRepository.InsertAsync(record);
                        //controlrecordlist.Add(record);
                    }
                    break;
                case "jinxiangcangdengjibiao"://进箱舱登记表
                    foreach (var item in baseList)
                    {
                        进箱舱登记表 record = new 进箱舱登记表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.Model, item.FisrtDrawingNum, item.FirstDrawingName);
                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.RecordStatus, item.Remarks, item.RecordRequire, item.RecordMainopoint);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstConfirmResult);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _enterRegisterRepository.InsertAsync(record);
                        //enterRegisterlist.Add(record);
                    }
                    break;
                case "tongyongjilubiao"://通用记录表
                    foreach (var item in baseList)
                    {
                        通用记录表 record = new 通用记录表(item.SerialNum, item.WorkStepEntityId, item.ProcessesEntityId, item.Sort, item.Model, item.FisrtDrawingNum, item.FirstDrawingName);
                        record.RecordRequirements = record.SetRecordRequirements(new RecordRequirementsEntity(), item.RecordRequire);
                        record.MeasuredResult = record.SetMeasuredResult(new MeasuredResultEntity(), item.FirstMeasuredValues, item.FirstConfirmResult);
                        record.InspectionSignature = record.SetInspectionSignature(new InspectionSignatureEntity());
                        await _generalRecordsRepository.InsertAsync(record);
                        //generalRecordslist.Add(record);
                    }
                    break;
            }

        }
    }
}
